package m.member.manage.service;

import m.common.model.util.ModelCheckUtil;
import m.common.model.util.ModelUpdateUtil;
import m.common.service.Service;
import m.member.manage.model.ServeGoods;
import m.system.exception.MException;
import m.system.util.GenerateID;
import m.system.util.ObjectUtil;

import java.sql.SQLException;

public class ServeGoodsService extends Service {
    public String save(ServeGoods model) throws MException, SQLException {
        ModelCheckUtil.checkNotNull(model,"title","description","type.oid","price","discount");
        ModelCheckUtil.checkUniqueCombine(model,new String[]{"title"},"商品已存在");
        String msg;
        if (ObjectUtil.isEmptyOid(model)) {
            model.setOid(GenerateID.generatePrimaryKey());
            ModelUpdateUtil.insertModel(model);
            msg="保存成功";
        }else{
            ModelUpdateUtil.updateModel(model,"title","description","type.oid","price","discount");
            msg="修改成功";
        }
        return msg;
    }
}
